//  
//-----------------------------------------------------------------------------

var in_ajax = 0;
var add_left = 0;
var add_top = 0;

//-----------------------------------------------------------------------------
//FUNCTIONS
//-----------------------------------------------------------------------------

    //-----------------------------------------------------------------------------
	function dragHandler(e){
		if (e == null) { e = window.event;} 
    	
		add_left= e.clientX;
		add_top = e.clientY;
		return true;
	}
    
    //---------------------------------------------------------------------
    // 
    function ShowHide(div_id) {
		if (document.getElementById(div_id).style.display == 'none') {
			document.getElementById(div_id).style.display = 'block';
			}
		else {
			document.getElementById(div_id).style.display = 'none';
			}	
	}
	
	//-----------------------------------------------------------------------------
	//
	function AddItem(id, what) {
		var wnd = document.getElementById("add_item_wnd");
		
		document.getElementById("add_item_caption").innerHTML = 'New ' + what;
		document.getElementById("add_item_form").action = '/' + what + '/add/';
		
		wnd.style.left = add_left + 'px';
		wnd.style.top = add_top + 'px';
		wnd.style.display = 'inline';
		wnd.style.visibility='visible';
	 	
	 	document.getElementById('id_name').focus();   
	}
	
	function HideWnd() {
		document.getElementById('add_item_wnd').style.visibility='hidden'
	}
	
	//-----------------------------------------------------------------------------
	//
	function TaskIsDone(id) {
		$.post('/task_is_done/', {"id": id}, function(data){ in_ajax = 0;});
		//$("#task_is_done"+id).html('<img src="/appmedia/done.gif">');
		var el = document.getElementById("task_is_done"+id); 
		if (el.alt == "undone") {
			el.src = "/appmedia/done.gif";
			el.alt = "done";
		}
		else {
			el.src = "/appmedia/undone.gif";
			el.alt = "undone";
		}
	}